#!/usr/bin/env python
# -*- coding:utf-8 -*-
#3.写代码有如下列表，按照要求实现每一个功能。
# li = ["alex","WuSir","ritian","barry","wenzhong"]

# 计算列表的长度并输出，
"""
result = len(li)
print(result)
"""

# 请通过步长获取索引为偶数的所有值，并打印出获取后的列表。
"""
li = ["alex","WuSir","ritian","barry","wenzhong"]
v=li[2::2]
print(v)
"""
# 列表中追加元素“seven”，并输出添加后的列表
"""
li = ["alex","WuSir","ritian","barry","wenzhong"]
li.append("seven")
print(li)
"""
# 请在列表的用第一个位置插入元素“tony”，并输出添加后的列表。
"""
li = ["alex","WuSir","ritian","barry","wenzhong"]
li.insert(0,"tony")
print(li)
"""
# 请修改列表第二个位置的元素为“Kelly”，并输出修改后的列表。
"""
li = ["alex","WuSir","ritian","barry","wenzhong"]
li[1] ="Kelly"
print(li)
"""
# 请将列表的第3个位置的值改为“太白”，并输出修改后的值
"""
li = ["alex","WuSir","ritian","barry","wenzhong"]
li[2]="太白"
print(li)
"""
# 请将列表 12=[1,"a",3,4,"heart"]每一个元素追加到列表li中  并输出添加后的列表
"""
li = ["alex","WuSir","ritian","barry","wenzhong"]
l2=[1,"a",3,4,"heart"]
for i in l2:
    li.append(i)
print(li)
"""
# 请将字符串 s="qwert"中的每一个元素添加到列表li中，不允许循环添加
"""
s = "qwert"
li = ["alex","WuSir","ritian","barry","wenzhong"]
# li.append(s[0])
# li.append(s[1])
# li.append(s[2])
# li.append(s[3])
# li.append(s[4])
for i in s:
    li.append(i)
print(li)
"""
# li = ["alex","WuSir","ritian","barry","wenzhong"]
# s = "qwert"
# li.extend(s)
# print(li)

# 请删除列表中的元素“ritian”，并输出添加后的列表
"""
li = ["alex","WuSir","ritian","barry","wenzhong"]
li.remove("ritian")
print(li)
"""
# 请删除列表中的第二个元素，并输出删除后的列表
"""
li = ["alex","WuSir","ritian","barry","wenzhong"]
li.pop(1)
print(li)
"""
# 请删除列表中的第二个到第四个元素，并输出删除后的列表
"""
li = ["alex","WuSir","ritian","barry","wenzhong"]
li.pop(1)
li.pop(1)
li.pop(1)
print(li)
"""







# 4请使用三种方法实现字符串旋转 name =“小黑半夜三点在被窝玩愤怒的小鸟” （步长，while，for）
# 第一种方法：
"""
name = "小黑半夜三点在被窝玩愤怒的小鸟"
name1=name[::-1]
print(name1)
"""
"""
# 第二种方法：
name = "小黑半夜三点在被窝玩愤怒的小鸟"
name_len = len(name)
count = 1
while count <= name_len:
    name1=name[-count]
    print(name1)
    count=count+1
"""
# 第三种方法：

# name = "小黑半夜三点在被窝玩愤怒的小鸟"
# a = ""
# index =14
# for i in name:
#     a=a+name[index]
#     index=index-1
# print(a)
# 第四种方法：
# range(0,10,1)  # 0 1 2 3 4 5 6 7 8 9
# range(9,-1,-1) #9 8 7 6 5 4 3 2 1 0
# name = "小黑半夜三点在被窝玩愤怒的小鸟"
# a = ""
# name_len = len(name)-1
# for i in range(name_len,-1,-1):
#     print(i)
#     a= a+name[i]
# print(a)
#
# 写代码，有如下列表，利用切片实现每一个功能

li = [1,3,2,"a",4,"b",5,"c"]
# 通过对li列表的切片形成新的列表[1,3,2]
# li1=li[0:3]
# print(li1)
# 通过对li列表的切片形成新的列表["a",4,"b"]
# a = li[3:6]
# print(a)
# 通过对li列表的切片形成新的列表[1,2,4,5]
# a = li[0::2]
# print(a)
# 通过对li列表的切片形成新的列表[3,"a","b"]
# a = li[1:-2:2]
# print(a)

# 6请用代码实现循环输出元素和值，：users = ["武佩奇","景女神","肖大侠"] 如：
# 0 武佩奇
# 1 景女神
# 2 肖大侠
"""
users = ["武佩奇","景女神","肖大侠"]
count=0
for i in users:
    print(count,i)
    count=count+1
"""
# 8.写代码，有如下列表，按照要求实现每一个功能。
# lis = [2,3,"k",["qwe",20,["k",["tt",3,"1"]],89],"ab","adv"]
# 将列表lis中的k变成大写，并打印列表
# lis[2]="K"
# print(lis)
# 将列表中的数字3变成字符串“100”。
# lis[1]=100
# print(lis)
# 将列表中的字符串“tt”变成数字101
# lis[3][2][1][0]=101
# print(lis)

# 在“qwe”前面加上字符串：“火车头”
# lis = [2,3,"k",["qwe",20,["k",["tt",3,"1"]],89],"ab","adv"]
# lis[3].insert(0,"火车头")
# print(lis)
# 9写代码实现以下功能  如有变量 goods = [‘汽车',"飞机"，"火箭"]

# 0,汽车
# 1,飞机
# 2,火箭
# 用户输入索引后，将指定商品拼接打印，如：用户输入0，则打印，您选择的商品是汽车。

goods = ["汽车","飞机","火箭"]
goods_len = len(goods)
for i in range(0,goods_len):
    print(i+1,goods[i])
num = input ("请输入您要选择的商品序号：")
num = int(num)
text = "您选择的商品是：%s"%(goods[num-1])
print(text)






"""
googe = ["0.汽车","1.飞机","2.火箭"]
print(googe)
a= input("请您输入商品索引：")
a=int(a)
if a == 0:
    print("汽车")
if a ==1:
    print("飞机")
if a == 2:
    print('火箭')
else:
    print("输入错误！")
"""
# 10请用代码实现 li="alex"  ,利用下划线将列表的每一个元素拼接成字符串”a_l_e_x.
"""
li= "alex"
result = "_".join(li)
print(result)
"""
# 利用for 循环和range 找出0-100以内所有的偶数，并追加到一个列表。
"""
a=[]
for i in range(1,100):
    if i%2 ==0:
        a.append(i)
print(a)
"""
# 12利用for 循环和range 找出0-50以内所有能被3整除的数，并追加到一个列表。
"""
a=[]
for i in range(1,50):
    if i%3 ==0:
        a.append(i)
print(a)
"""
# 13利用for 循环和range 找出0-50以内所有能被3整除的数，并插入到列表第0个索引位置，最终结果如下：[48,45,....]
# a=[]
# for i in range(1,50):
#     if i%3 ==0:
#         a.insert(0,i)
# print(a)
# 14查找列表li中的元素，移除每个元素中空格，并找出以“a”开头，并添加到一个新列表中，最后循环打印这个新列表。
"""
li = ["TaiBai","alexC","AbC ","egon"," riTiAn","WuSir"," aqc"]
a= []
for i in li:
    b=i.strip()
    print(b)
    flag = b.startswith("a")
    if flag ==True:
        a.append(b)
print(a)
"""

# 15判断是否可以实现，如果可以请写代码实现。
li = ["alex",[11,22,(89,99,100),33],"WuSir",("ritian","barry"),"wenzhong"]
# 请将"WuSir"改成“武佩奇”
"""
li[2]= "武佩奇"
print(li)
"""

"""
#   请将“wenzhong”，然后再列表的第0个位置添加“文周”
li.remove("wenzhong")
li.insert(0,"文周")
print(li)
"""
